<?php
/**
 * Created by PhpStorm
 * User: Jhinwy
 * Date: 7/24/24
 * Time: 2:06 PM
 */

namespace app\common\model\order;


use app\common\model\app\App;
use app\common\model\auth\Admin;
use app\common\model\BaseModel;
use app\common\model\media\MediaAccount;
use app\common\model\promotion\PromotionLink;
use app\common\model\return_rule\ReturnRule;


class OrderCallback extends BaseModel
{

    protected $name = 'order_callback';


    // 染色时间
    public function getDyeingTimeAttr($value)
    {
        return date('Y-m-d H:i:s', $value);
    }

    // 上报时间
    public function getReportingTimeAttr($value, $data)
    {
        if (!empty($data['reporting_time'])) {
            $data['reporting_time'] = date('Y-m-d H:i:s', $data['reporting_time']);
        } else {
            $data['reporting_time'] = '';
        }
        return $data['reporting_time'];
    }


    /**
     * 回传规则
     *
     * @return \think\model\relation\HasOne
     */
    public function channel()
    {
        return $this->hasOne(ReturnRule::class, 'id', 'return_rule_id');
    }


    /**
     * 应用
     *
     * @return \think\model\relation\HasOne
     */
    public function app()
    {
        return $this->hasOne(App::class, 'id', 'app_id');
    }


    /**
     * 订单
     *
     * @return \think\model\relation\HasOne
     */
    public function orders()
    {
        return $this->hasOne(Order::class, 'id', 'order_id');
    }


    /**
     * 媒体账户
     *
     * @return \think\model\relation\HasOne
     */
    public function account()
    {
        return $this->hasOne(MediaAccount::class, 'id', 'media_account_id');
    }


    /**
     * 推广链
     *
     * @return \think\model\relation\HasOne
     */
    public function link()
    {
        return $this->hasOne(PromotionLink::class, 'id', 'promotion_link_id');
    }

    /**
     * admin
     *
     * @return \think\model\relation\HasOne
     */
    public function admin()
    {
        return $this->hasOne(Admin::class, 'id', 'admin_id');
    }

}
